﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SheShuiDXFL.aspx.cs" Inherits="Web.Pages.YongShui.JiChuXX.SheShuiDXFL" Theme="Default" %>
<%@ Register Assembly="DevExpress.Web.v15.2, Version=15.2.9.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web" TagPrefix="dx" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <script src="../../../JS/AddEditCancel.js"></script>
    <script src="../../../JS/jquery.js"></script>
    <script type="text/javascript">
        function keyEnter(index) {
            var controls = new Array();
            controls[0] = document.getElementById("txtNo_I");
            controls[1] = document.getElementById("txtName_I");
            var key = event.keyCode;
            if (key == 13) {
                index = index + 1;
                if (index == controls.length) {
                    index = 0;
                }
                controls[index].focus();
            }
        }
    </script>
    <script type="text/javascript">
        function display(op, id) {
            hdCollection.Set("ID", id);
            if (op == "add") {
                btnAdd.SetVisible(false);
                lblOperateTip.SetText("添加");
                txtNo.SetText("");
                txtNo.SetEnabled(true);
                txtName.SetText("");
                txtName.SetEnabled(true);
                listCover(true, "divList");
                $("#GridViewContentTable").show();
                txtNo.Focus();
            }
            else if (op == "edit") {
                btnAdd.SetVisible(false);
                lblOperateTip.SetText("修改");
                txtNo.SetEnabled(false);
                txtName.SetEnabled(true);
                listCover(true, "divList");
                $("#GridViewContentTable").show();
                ASPxCallback1.PerformCallback("info");
            }
            else {
                $("#GridViewContentTable").hide();
                btnAdd.SetVisible(true);
                listCover(false, "divList");
            }
        }

        function del(id) {
            hdCollection.Set("ID", id);
            if (confirm("确认删除吗？")) {
                ASPxCallback1.PerformCallback("del");
            }
            else {
                hdCollection.Set("ID", -1);
            }
        }

        function save() {
            if (txtNo.GetText() == "") {
                alert("请输入代码编号！");
                txtNo.Focus();
                return;
            }
            if (!isAllNum(txtNo.GetText())) {
                alert("你输入的格式不正确，请输入数字类型！");
                txtNo.Focus();
                return;
            }
            if (txtName.GetText() == "") {
                alert("名称不能为空！");
                txtName.Focus();
                return;
            }
            ASPxCallback1.PerformCallback("save");
        }

        function ASPxCallback1Complete(rs) {
            var arr = rs.split('|');
            var type = arr[0];
            var state = arr[1];
            var specialIdentity = arr[2];
            var msg = arr[3].split('-');
            if (msg[0] == 'True') {
                alert(msg[1]);
            }
            hdCollection.Set("type", type);
            if (state == 'True') {
                if (type == "info") {
                    //加载信息
                    txtNo.SetText(arr[4]);
                    txtName.SetText(arr[5]);
                    txtName.Focus();
                }
                else if (type == "del") {
                    gvList.PerformCallback();
                }
                else if (type == "save") {
                    display("init", -1);
                    hdCollection.Set("OperateID", specialIdentity);
                    gvList.PerformCallback();
                }
            }
            else {

            }
        }

        function begincall() {
            loadpanel1.Show();
        }
        function endcall() {
            loadpanel1.Hide();
            //定位添加或修改的记录
            var oid = hdCollection.Get("OperateID");
            var index = -1;
            if (oid != -1 && typeof (oid) != undefined) {
                for (var i = 0; i < gvList.GetVisibleRowsOnPage() ; i++) {
                    if (gvList.GetRowKey(i) == oid) {
                        index = i;
                    }
                }
                if (index != -1) {
                    gvList.SetFocusedRowIndex(index);
                    gvList.MakeRowVisible(index);
                    hdCollection.Set("OperateID", -1);
                }
            }
        }
        </script>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
        <div class="tabletitle1">
            涉水对象分类
        </div>
         <dx:ASPxHiddenField ID="hdCollection" ClientInstanceName="hdCollection" runat="server"></dx:ASPxHiddenField>
            <dx:ASPxCallback ID="ASPxCallback1" ClientInstanceName="ASPxCallback1" runat="server" OnCallback="ASPxCallback1_Callback" ClientSideEvents-CallbackComplete="function(s,e){ASPxCallback1Complete(e.result);}"></dx:ASPxCallback>
        <dx:ASPxLoadingPanel ID="ASPxLoadingPanel1" ClientInstanceName="loadpanel1" runat="server" ContainerElementID="gvList" Modal="true" Theme="Metropolis" ShowImage="false" Text="加载中" ></dx:ASPxLoadingPanel>
        <asp:UpdatePanel runat="server">
            <ContentTemplate>
                <div align="center">
                    <div id="divList" runat="server">
                        <dx:ASPxGridView ID="gvSheShuiDXFL" ClientInstanceName="gvList" runat="server" AutoGenerateColumns="False" KeyFieldName="ID" Theme="Aqua1" Width="100%">
                            <Columns>
                                <dx:GridViewDataTextColumn FieldName="S_DAIMA" Caption="代码" Width="10%">
                                </dx:GridViewDataTextColumn>
                                <dx:GridViewDataTextColumn FieldName="S_NAME" Caption="名称" Width="60%">
                                </dx:GridViewDataTextColumn>
                                <dx:GridViewDataTextColumn Width="4%">
                                    <DataItemTemplate>
                                        <a href="#" onclick="display('edit','<%#Eval("ID")%>')">修改</a>
                                    </DataItemTemplate>
                                </dx:GridViewDataTextColumn>
                                <dx:GridViewDataTextColumn Width="4%">
                                    <DataItemTemplate>
                                        <a href="#" onclick="del('<%#Eval("ID")%>')">删除</a>
                                    </DataItemTemplate>
                                </dx:GridViewDataTextColumn>
                            </Columns>
                            <Settings VerticalScrollableHeight="350" VerticalScrollBarMode="Auto" />
                            <ClientSideEvents  Init="function(s,e){AdjustSize(250,gvList);}" BeginCallback="function(s,e){begincall();}" EndCallback="function(s,e){endcall();}"/>
                        </dx:ASPxGridView>
                    </div>
                    <div style="height: 3px;"></div>
                    <div style="text-align: right">
                        <hr />
                        <dx:ASPxButton ID="btnAdd" ClientInstanceName="btnAdd" runat="server" Text="添加" AutoPostBack="false"  ClientSideEvents-Click="function(s,e){display('add',-1)}"  UseSubmitBehavior="false">
                        </dx:ASPxButton>
                    </div>
                    <div id="GridViewContentTable" style="display:none;">
                        <div class="tabletitle1" align="center">
                           <dx:ASPxLabel ID="lblOperateTip" runat="server" ClientInstanceName="lblOperateTip" Text="添加"></dx:ASPxLabel>
                        </div>
                        <table>
                            <tr style="height: 40px">
                                <td>代码：</td>
                                <td>
                                    <dx:ASPxTextBox ID="txtNo" ClientInstanceName="txtNo" runat="server" MaxLength="15" Width="100">

                                        <ClientSideEvents KeyPress="function(s,e){OnKeyNext(txtName);}" />
                                    </dx:ASPxTextBox>
                                </td>
                            </tr>
                            <tr>
                                <td>名称：</td>
                                <td>
                                    <dx:ASPxTextBox ID="txtName" ClientInstanceName="txtName" runat="server" MaxLength="30" Width="250">

                                        <ClientSideEvents KeyPress="function(s,e){OnKeyNext(btnSave);}" />
                                    </dx:ASPxTextBox>
                                </td>
                            </tr>
                        </table>
                        <div align="right">
                            <hr />
                            <table id="GridViewButtonTable" runat="server">
                                <tr>
                                    <td style="text-align: center;">
                                       <dx:ASPxButton ID="ASPxButton1" ClientInstanceName="btnSave" runat="server" Text="保存" AutoPostBack="false" UseSubmitBehavior="false" ClientSideEvents-Click="function(s,e){save();}">
                                    </dx:ASPxButton>
                                    <dx:ASPxButton ID="btnCancel" runat="server" Text="放弃" AutoPostBack="false" ClientSideEvents-Click="function(s,e){display('init',-1);}" UseSubmitBehavior="false">
                                    </dx:ASPxButton>
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </div>
                </div>
            </ContentTemplate>
        </asp:UpdatePanel>
    </form>
</body>
</html>
